<?php
namespace Model;

use Zend\Db\Adapter\Adapter;
use Zend\Db\Sql\Predicate\Like;
use Zend\Db\Sql\Predicate\Operator;
use Zend\Db\Sql\Select;
use Zend\InputFilter\InputFilter;

class RestaurantTable extends AbstractTable
{

    /**
     * @param $id
     * @return Restaurant
     */
    public function getRestaurant($id){
       return $this->getById($id);
    }

    /**
     * @return InputFilter
     */
    public function getInputFilter()
    {
        $filter = new InputFilter();

        return $filter;
    }

    public function search($isPaging, $offset, $rowPerPage, $orderArr = array('created_date'), $searchOption){

        $select = $this->getDbSqlSelect();


        if($isPaging){
            $select->offset($offset)->limit($rowPerPage);
        }

        if($orderArr){
            $select->order($orderArr);
        }

        $rows = $this->tableGateway->selectWith($select);
        $result['rows'] = $rows;

        $total = $this->getCount($select);

        $result['total'] = $total;

        return $result;

    }

    public function getDomainOfUser($id, $active = 1)
    {
        $select = $this->getDbSqlSelect();
        $select->join(array('du'=>'domain_user'), 'du.domain_id = restaurant.id', array())
        ->where(array('du.active'=>$active, 'du.user_id'=>$id, 'restaurant.active'=>$active));
        return $this->executeSelectForArray($select);
    }

    /**
     * @param string $domainCode
     * @return Restaurant
     */
    public function getByDomainCode($domainCode){
        return $this->getByColumn('domain', $domainCode)->current();
    }

}